package com.example.demo1.wyy.service.impl;


import com.example.demo1.wyy.model.LegalPerson;
import com.example.demo1.wyy.model.vo.LegalPersonAddVo;
import com.example.demo1.wyy.repository.LegalPersonReposirtory;
import com.example.demo1.wyy.service.LegalPersonService;
import com.example.demo1.wyy.util.Result;
import com.example.demo1.wyy.util.ResultVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * Created by Lx on 2018/6/27.
 */
@Service
public class LegalPersonServiceImpl implements LegalPersonService {

    @Autowired
    private LegalPersonReposirtory legalPersonReposirtory;
    private final static AtomicInteger idGenerator = new AtomicInteger();
    @Override
    @Transactional
    public Result<LegalPersonAddVo> addLegalPerson(LegalPersonAddVo legalPersonAddVo) {
        LegalPerson legalPerson = new LegalPerson();
        BeanUtils.copyProperties(legalPersonAddVo,legalPerson);
        Integer id = idGenerator.incrementAndGet();
        legalPerson.setId(id);
        legalPersonReposirtory.save(legalPerson);
        System.out.println(legalPerson.getId());
        return ResultVO.success(legalPersonAddVo);
    }
}
